package com.pxmeta.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.party.entity.vo.GiftItemsVO;
import com.pxmeta.party.service.IPartyGiveGiftService;
import com.pxmeta.user.entity.dto.UserWithdrawDTO;
import com.pxmeta.user.entity.dto.WithdrawExportDTO;
import com.pxmeta.user.entity.vo.UserBillVO;
import com.pxmeta.user.entity.vo.UserWithdrawVO;
import com.pxmeta.user.service.IUserBillService;
import com.pxmeta.user.service.IUserWithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(value = "账单管理",tags = "账单管理")
@RequiredArgsConstructor
@RequestMapping("/userBill")
@CrossOrigin
public class UserBillController {
    private final IUserWithdrawService userWithdrawService;
    private final IPartyGiveGiftService partyGiveGiftService;
    private final IUserBillService userBillService;

    @GetMapping("/getGiveGiftRecords")
    @ApiOperation("获取赠送礼物记录")
    public AjaxResult getGiveGiftRecords(@RequestParam Integer page,
                                         @RequestParam Integer size){
        IPage<GiftItemsVO> result = partyGiveGiftService.getPartyGiveGiftPage(page, size);
        return AjaxResult.successPage(result.getRecords(),result.getTotal());
    }

    @GetMapping("/getUpdateBalanceList")
    @ApiOperation("获取修改金币记录")
    public AjaxResult updateBalanceList(@RequestParam Integer page,
                                        @RequestParam Integer size){
        IPage<UserBillVO> result = userBillService.getSystemUpdateBalanceList(page,size);
        return AjaxResult.successPage(result.getRecords(), result.getTotal());
    }


    @GetMapping("/getWithdrawList")
    @ApiOperation("获取提现列表")
    public AjaxResult getWithdrawList(@RequestParam Integer page,
                                      @RequestParam Integer size,
                                      @RequestParam(required = false) Integer status,
                                      @RequestParam(required = false) String keyword) {
        IPage<UserWithdrawVO> result = userWithdrawService.getWithdrawList(page, size, status);
        return AjaxResult.successPage(result.getRecords(), result.getTotal());
    }

    @PostMapping("/verify")
    @ApiOperation("审核提现")
    public AjaxResult verify(@RequestBody UserWithdrawDTO dto){
        userWithdrawService.confirmWithdraw(dto);
        return AjaxResult.success();
    }

    @GetMapping("/exportList")
    @ApiOperation("导出数据")
    public AjaxResult exportList(HttpServletResponse response,
                                 @RequestParam Integer page,
                                 @RequestParam Integer size,
                                 @RequestParam(required = false) Integer status){
        IPage<UserWithdrawVO> result = userWithdrawService.getWithdrawList(page, size, status);
        userWithdrawService.export(response, "提现数据",result.getRecords(), UserWithdrawVO.class);
        return AjaxResult.success();
    }

}
